/**
 * created by dt 2025-05-08
 * 技能释放系统
 */

import { System } from "../../core/System";
import { ecs_trait, ecs_trait_property } from "../../core/Trait";
import { Skill } from "../../skill/shell/Skill";
import { SkillInstance } from "../../skill/core/SkillInstance";
import { ECSkillInstance } from "../components/ECSkillInstance";
import { ECSkillManager } from "../components/ECSkillManager";

@ecs_trait()
class SkillCastTrait {
    @ecs_trait_property(ECSkillManager)
    skillManager!: ECSkillManager;
}

export class SkillCastSystem extends System {
    onStart(): void {
    }

    onUpdate(deltaTime: number): void {
        this.world.forEach(SkillCastTrait, (bundle) => {
            // 1.选择技能
            const skill = this.selectSkill(bundle.skillManager);

            if (!skill) {
                return;
            }

            // 3. 释放技能
            this.cast(skill);
        });
    }

    private selectSkill(skillManager: ECSkillManager): Skill {
        // 1.默认优先级
        return skillManager.skills[0];
    }

    private checkConditions(skill: Skill): boolean {
        return true;
    }

    private cast(skill: Skill): void {
        // 1.选择
        // 创建一个技能实例，绑定到ECSKillInstance组件
        // const skillEntity = this.world.createEntity();
        // skillEntity.addComponent(ECSkillInstance, {
        //     skill: skill,
        // });
    }
}


